@extends('layouts.app')

@section('content')
<!-- Main content -->
<section class="content">
  <div class="row">
    <div class="col-xs-12">
      @include('layouts.utils.success')
      <div class="box">
        <div class="box-header">
          <a href="{{ url('/api_admin/permission/create') }}" class="btn btn-primary">添加新权限</a>
        </div>
        <!-- /.box-header -->
        <div class="box-body table-responsive no-padding">
          <table class="table table-hover">
            <tr>
              <th style="width: 50px;">ID</th>
              <th>Name</th>
              <th>权限名</th>
              <th>权限描述</th>
              <th>创建日期</th>
              <th style="width: 50px;">操作</th>
            </tr>
            @forelse($permissions as $permission)
            <tr>
              <td>{{ $permission->id }}</td>
              <td>{{ $permission->name }}</td>
              <td>
                <a href="{{ url('/api_admin/permission/'.$permission->id.'/edit') }}">
                  {{ $permission->display_name }}
                </a>
              </td>
              <td>{{ $permission->description }}</td>
              <td>{{ $permission->created_at }}</td>
              <td>
                <form id="del-{{ $permission->id }}" method="post" action="{{ url('/api_admin/permission/'.$permission->id) }}">
                  {!! csrf_field() !!}
                  {{ method_field('DELETE') }}
                  <a style="cursor: pointer;" onclick="del({{$permission->id}})">删除</a>
                </form>
              </td>
            </tr>
            @empty
              <tr>
                <td colspan="6" class="text-center">暂无数据</td>
              </tr>
            @endforelse
          </table>
          @include('layouts.utils.del_modal', ['title' => '权限'])
        </div>
        <div class="box-footer">
          {!! $permissions->links() !!}
        </div>
        <!-- /.box-body -->
      </div>
      <!-- /.box -->
    </div>
  </div>
</section>
<!-- /.content -->
@endsection

@section('js')
<script type="text/javascript">
  function del(id){
    var formId = 'del-'+id;
    $('#delete-modal').modal();
    $('#del-btn').on('click', function() {
      $('#'+formId).submit();
    });
  }
</script>
@endsection
